LGF_FIFO (FB / 4.0.0)

Overview

Author: Siemens Industry Support

Short description

FIFO (First-In First-Out / Queue / ring buffer memory)
The function stores incoming data and outputs the oldest unprocessed data.

Block Interface

LGF_FIFO (FB)
Bool  enable valid  Bool
    
Bool  enqueue busy  Bool
    
Bool  dequeue error  Bool
    
Bool  reset status  Word
    
Bool  clear elementCount  DInt
    
Variant  initialItem isEmpty  Bool
    
   isFull  Bool
    
   diagnostics  LGF_typeDiagnostics
    
Variant  item  Variant
       
Variant  buffer  Variant
       
   

Input parameter

IdentifierData type Default value Description
enableBool FALSE TRUE: Enable functionality of FB
enqueueBool false Enqueue item to the buffer
dequeueBool false Dequeue item from the buffer and return it on `item`
resetBool FALSE Initializing the buffer (reset the index and the counter)
clearBool FALSE Clearing the buffer and initialize with the initial value `initialItem` (Reset index and counter).
initialItemVariant --- Value with which the ARRAY of the buffer is initialized
(usually: `0` / default value)

Output parameter

IdentifierData type Description
validBool TRUE: Valid set of output values available at the FB
busyBool TRUE: FB is active and new output values can be expected
errorBool FALSE: No error
TRUE: An error occurred during the execution of the FB
statusWord 16#0000-16#7FFF: Status of the FB
16#8000-16#FFFF: Error identification (see following Table)
elementCountDInt Number of elements in the buffer
isEmptyBool TRUE: Buffer is empty
isFullBool TRUE: Buffer is full
diagnosticsLGF_typeDiagnostics Diagnostic structure to store and transfer diagnostic information from blocks through the interface.

In/Out parameter

IdentifierData type Description
itemVariant The entry that is either returned from the ring buffer or written into the buffer
bufferVariant The ARRAY that is used as the ring buffer. (Array of…)

Status & Error codes

Code / ValueIdentifier / Description
16#0000STATUS_NO_ERROR
Status: Execution finished without errors
16#7000STATUS_NO_CURRENT_JOBS
Status: No current jobs, initial state
16#7001STATUS_FIRST_CALL
First call after incoming new job (rising edge 'enable')
16#7002STATUS_SUBSEQUENT_CALL
Status: Subsequent call during active processing without further details
16#8001ERR_BUFFER_EMPTY
Error: The buffer is empty
16#8002ERR_BUFFER_FULL
Error: The buffer is full
16#8200ERR_NO_ARRAY
Error: No array is present at the input `buffer`
16#8201ERR_WRONG_TYPE_ITEM
Error: The data type of the InOut parameter `item` does not correspond to the data type of the array elements of the input `buffer`
16#8202ERR_WRONG_TYPE_INITIAL_ITEM
Error: The data type of the input `initialValue` does not correspond to the data type of the InOut parameter `item`
16#8203ERR_BOOL_NOT_SUPPORTED
Error: Boolean variables and arrays are not supported by `MOVE_BLOCK_VARIANT`. (Use a PLC Datatype instead)
16#8204ERR_MULTIPLE_COMMANDS_DEDECTED
Error: Multiple commands in the same cycle detected
16#8600ERR_UNDEFINED_STATE
Error: Due to an undefined state in state machine
16#8601ERR_INDEX_IN_ARRAY_LIMITS_1
Error: The tag `statNextEmptyItemIndex` is not within the array limits
16#8602ERR_INDEX_IN_ARRAY_LIMITS_2
Error: The tag `statFirstItemIndex` is not within the array limits
16#8610ERR_CLEAR_BUFFER
Error: While clearing buffer in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code
16#8611ERR_RETURN_FIRST_ENTRY
Error: While return first entry of buffer in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code
16#8612ERR_REPLACE_ITEM_BY_INIT_VALUE
Error: While replace item by initial value in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code
16#8613ERR_WRITE_ENTRY
Error: While write entry to buffer in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code

User defined datatype(s)

LGF_typeDiagnostics (UDT / V1.0.1)

Diagnostic structure to store and transfer diagnostic information from blocks through the interface.

Identifier Data type Default value Description
status Word 16#0000 Status of the Block or error identification when error occurred
subfunctionStatus Word 16#0000 Status or return value of called FB's, FC's and system blocks
stateNumber DInt 0 State in the state machine of the block where the error occurred

Functional description

NOTE
The status of called commands is output in subFunctionStatus. In this case, the output value in status indicates which command caused the error. In this case, refer to the TIA Portal Online Help section for information on the respective commands.

NOTE
In computer science, the queue is also based on the FIFO principle.

With the enqueue input, a new item is stored from the InOut parameter item in the next free position in the buffer. The output elementCount is incremented by one.

With the dequeue input, the next element to be processed is output to the InOut parameter item, and this field in the buffer is replaced by the value in the parameter initialItem. The output elementCount decremented by one.

With the reset input, the buffer is initialized, and the index and counter are reset. The elementCount output is set to zero and the isEmpty output is set to TRUE.

With the clear input, the buffer is emptied and initialized with the initial value initialItem. Index and counter are reset. The elementCount output is set to zero and the isEmpty output is set to TRUE.

Change log

Version & DateChange description
1.0.0Siemens Industry Online Support
19.08.2015First released version
1.0.1Siemens Industry Online Support
16.11.2015Bug fix resetBuffer
1.0.2Siemens Industry Online Support
02.01.2017Upgrade: TIA Portal V14 Update 1
1.0.3Siemens Industry Online Support
17.08.2018Upgrade: TIA V15 Update 2
1.0.4Siemens Industry Online Support
23.11.2018Upgrade: TIA V15.1
2.0.0Siemens Industry Online Support
29.01.2019Output "done" removed (not necessary, because block works synchronous)
3.0.0Simatic Systems Support
22.10.2019Code refactoring, comments added
Interface change (enqueue, dequeue etc.)
Set version to V3.0.0, harmonize the version of the whole library
3.0.1Simatic Systems Support
15.02.2021Insert documentation
4.0.0Simatic Systems Support
04.09.2024Rework to PLC Open `Enable` behavior
Add `isFull` outputs
Fix Bug while filling after left shift operation
Rework to diagnostic output datatype